package demo.hbase.test;

import lombok.extern.slf4j.Slf4j;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description TODO
 * @Author 作者： chenMing
 * @DATE 创建时间： 2023/11/21 11:07
 * @Version 版本：cmBoot1.0
 */
@Slf4j
public class HbaseUtil2 {

    /**
     * Hbase数据库 调用的特定链接方式
     * @param dto
     * @return
     */
   public static List<String> hbaseConnection(DbConfigParamDto dto) {
        List<String> list = new ArrayList<>();

        // 配置 HBase 连接
        Configuration conf = HBaseConfiguration.create();
        conf.set("hbase.zookeeper.quorum", "172.16.11.56");
        conf.set("hbase.zookeeper.property.clientPort", "2181");
//        conf.set("hbase.master", "172.16.11.56:60000");
        String instanceName =null;
       // 连接HBase并判断是否成功
       try (Connection connection = ConnectionFactory.createConnection(conf)) {
           System.out.println("HBase connection successful");
           if(conf.getBoolean("hbase.cluster.distributed",false)){
           instanceName = conf.get("hbase.rootdir");
       } else {
           instanceName = "default";
       }

       } catch (Exception e) {
           System.out.println("HBase connection failed: " + e.getMessage());
       }
       return list;
    }


}
